#ifndef HTMLELEMENT_H
#define HTMLELEMENT_H
#include <AbsElement.h>
#include "EleFactory.h"
#define OVERRIDE_FUNC setNameStr(this->metaObject()->className());
#include <QDebug>
class  HtmlElement : public AbsElement
{
    Q_OBJECT
public:
    explicit  HtmlElement( QObject *prent = nullptr);
    HtmlElement(const HtmlElement &ele, QObject *prent =nullptr);
    QList<AbsElement *> getEleContext() const;
    void setEleContext(const QList<AbsElement *> &value);


    // AbsElement interface
    QString getText() const;

public :
    ///接口函数
    /**
     * @brief alignCenter 居中显示
     */
    virtual void alignCenter();
    /**
     * @brief alignLeft 居左显示
     */
    virtual void alignLeft();
    /**
     * @brief 居右显示
     */
    virtual void alignRight();
    /**
     * @brief setBoder 设置元素的边距 参照 HTML 的boder属性或者Css的boder属性格式
     * @param boderStr  boder 的格式
     */
    // virtual void setBoder(QString boderStr);

    // virtual void setMagin();


    /**
     * @brief appendElement  元素嵌套 当前 元素 里面包含 一个  ele 元素
     *  如 < 当前元素 > <ele> </ele>  </当前元素>
     * @param ele
     */
    // AbsElement interface


    virtual void appendElement(AbsElement *ele) Q_DECL_OVERRIDE;

    //!
    //! \brief setContent
    //! \param value
    //!
    virtual void setContent(const QString &value);



protected:
    virtual void initMate() Q_DECL_OVERRIDE;
    virtual void clear() Q_DECL_OVERRIDE;
    virtual QString context() Q_DECL_OVERRIDE;

private:
    QString eleString();
private:
    QList<AbsElement*> eleContext;
    QString text;
    HtmlElement * outEle;


    // AbsElement interface
public:
    virtual void setOutObj(HtmlElement *ele) Q_DECL_OVERRIDE;
    virtual HtmlElement *getOutObj() Q_DECL_OVERRIDE;
};
















class Div :public HtmlElement{
    Q_OBJECT
public:

    Div(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{
        OVERRIDE_FUNC
    }
};
Q_DECLARE_METATYPE(Div);







class Table:public HtmlElement
{
    Q_OBJECT
public:
    Table(QObject *prent =nullptr):HtmlElement(prent){
        AbsElement::setAttrbute("cellspacing","0");
        AbsElement::setAttrbute( "cellpadding","0");
        QString str ="border-collapse:collapse;border:none;width:auto;margin: 0;padding: 0;";
        QStringList item = str.split(";");
        QMap<QString,QString> style;
        for(int i = 0 ;i<item .size();i++){
            if(item[i]=="") continue;
            QStringList strList= item[i].split(":");
            style[strList[0]] = strList[1];
        }
        AbsElement::setStyleSheet(style);
    }

    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(Table);


class Tr:public HtmlElement
{
    Q_OBJECT
public:
    Tr(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(Tr);


class Td:public HtmlElement
{
    Q_OBJECT
public:
    Td(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(Td);

class P:public HtmlElement
{
    Q_OBJECT
public:
    P(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(P);


class Span:public HtmlElement
{
    Q_OBJECT
public:
    Span(QObject *prent =nullptr):HtmlElement(prent){
        setStyleSheet("background-size","100% 100%");
        setStyleSheet("display","block");
    }

    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
    // HtmlElement interface
public:
    virtual void setEleHeight(int height) Q_DECL_OVERRIDE{
        setStyleSheet("height",QString("%1px").arg(height));
    }
    virtual void setEleWidth(int width)Q_DECL_OVERRIDE{
        setStyleSheet("width",QString("%1px").arg(width));
    }

    // AbsElement interface


    // HtmlElement interface
public:
    virtual void setContent(const QString &value) Q_DECL_OVERRIDE{
        setStyleSheet("background-image",tr( " url('%1') ").arg(value));
        qDebug()<<this->metaObject()->className();
    }
};
Q_DECLARE_METATYPE(Span);

class Img:public HtmlElement{
    Q_OBJECT
public:
    Img(QObject *prent = nullptr):HtmlElement(prent){}


    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
    // HtmlElement interface
public:
    virtual void setEleHeight(int height) Q_DECL_OVERRIDE{
        setAttrbute(tr("height"),QString::number( height));
    }
    virtual void setEleWidth(int width)Q_DECL_OVERRIDE{
        setAttrbute(tr("width "),QString::number( width));
    }

    // HtmlElement interface
public:
    virtual void setContent(const QString &value) Q_DECL_OVERRIDE;

    // AbsElement interface
public:
    virtual void appendElement(AbsElement *ele) Q_DECL_OVERRIDE;
};
Q_DECLARE_METATYPE(Img);
class Hr:public HtmlElement
{
    Q_OBJECT
public:
    Hr(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(Hr);
class H1:public HtmlElement
{
    Q_OBJECT
public:
    H1(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(H1);


class H2:public HtmlElement
{
    Q_OBJECT
public:
    H2(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(H2);
class H3:public HtmlElement
{
    Q_OBJECT
public:
    H3(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(H3);
class H4:public HtmlElement
{
    Q_OBJECT
public:
    H4(QObject *prent =nullptr):HtmlElement(prent){}
    // AbsElement interface
protected:
    virtual void initMate() Q_DECL_OVERRIDE{OVERRIDE_FUNC}
};
Q_DECLARE_METATYPE(H4);
#endif // HTMLELEMENT_H
